package com.cms.portal.freemarker;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.view.freemarker.FreeMarkerView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author laolang
 * @version 1.0.0
 * @ClassName CmsViewResolver
 */
@Slf4j
public class CmsViewResolver  extends FreeMarkerView {

    private  static final String ADMIN_PATH = "/admin/cms";

    @Override
    protected void exposeHelpers(Map<String, Object> model, HttpServletRequest request) throws Exception {
        //返回除去host(域名或者ip)部份的路径
        String requestURI = request.getRequestURI();
        //获取根目录路径
        String contextPath = request.getContextPath();
        //获取能够与web.xml中的<servlet-mapping>标签中“url-pattern”中匹配的路径，注意是完全匹配的部分，*的部份不包括
        String servletPath = request.getServletPath();
      /*  log.info(url);
        log.info(contextPath);
        log.info(servletPath);*/
        //默认后台请求路径
        if(requestURI.contains(ADMIN_PATH)){

            model.put("adminPath",contextPath+servletPath);
        }
        model.put("basePath",contextPath);


    }
}

